package com.yonyou.chuan.log;

import nccloud.baseapp.core.log.LoggerTool;
import org.slf4j.helpers.MessageFormatter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LoggerUtil {

    private long t_st = System.currentTimeMillis();
    private long s_st = System.currentTimeMillis();
    private static String LOGGER_NAME = "nccforuap";

    public static void printLogger(String str,Object... obj){
        DateFormat df = new SimpleDateFormat("HH:mm:ss");
        String st = df.format(new Date());
        StringBuilder sb = new StringBuilder();
        sb.append(st + " ["+LOGGER_NAME+"@" + Integer.toHexString(Thread.currentThread().hashCode()) + "]" + str );
        String msg = MessageFormatter.arrayFormat(sb.toString(), obj).getMessage();
        LoggerTool.log(LOGGER_NAME, "debug", msg, (Throwable)null);
    }

    public void printStepCost(String s,Object... obj) {
        DateFormat df = new SimpleDateFormat("HH:mm:ss");
        String st = df.format(new Date());
        StringBuilder sb = new StringBuilder();
        sb.append(st + " ["+LOGGER_NAME+"@" + Integer.toHexString(Thread.currentThread().hashCode()) + "]" + s + " cost: " + (System.currentTimeMillis() - this.s_st) + " ms");
        String msg = MessageFormatter.arrayFormat(sb.toString(), obj).getMessage();
        LoggerTool.log(LOGGER_NAME, "debug", msg, (Throwable)null);
        this.s_st = System.currentTimeMillis();
    }

    public void printTotalCost(String s,Object... obj) {
        DateFormat df = new SimpleDateFormat("HH:mm:ss");
        String st = df.format(new Date());
        StringBuilder sb = new StringBuilder();
        sb.append(st + " ["+LOGGER_NAME+"@" + Integer.toHexString(Thread.currentThread().hashCode()) + "]" + s + " cost: " + (System.currentTimeMillis() - this.t_st) + " ms");
        String msg = MessageFormatter.arrayFormat(sb.toString(), obj).getMessage();
        LoggerTool.log(LOGGER_NAME, "debug", msg, (Throwable)null);
    }
}
